<?
if(isset($is_guest))
    header("location: $PHP_SELF?i=2");
/***************************************************************************
 Jupiter Content System @ Highstrike.net
 Copyright (C) 2005 Cosmin Flavius (highstrike@gmail.com)

 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.

 More Info About The Licence At http://www.gnu.org/copyleft/gpl.html
****************************************************************************/

switch($a)
{
	//-----------------------------------------------------------------
	//  View profile case
	//-----------------------------------------------------------------

	case 1:

		//-----------------------------------------------------------------
		//  Load the user's row + Check for existance
		//-----------------------------------------------------------------

		$user = $db->getLine("SELECT * FROM users",$d);
		if(!$user) header("location: $PHP_SELF?i=error");

		//-----------------------------------------------------------------
		//  Hide email if option says so
		//-----------------------------------------------------------------

		if($user['hideemail'] == 1 && !isset($is_administrator) && !isset($is_webmaster)) $email = "<span class='inv'>{$language['Users profile desc18']}</span>";
		elseif($user['hideemail'] == 1) $email = "<a href='mailto:{$user['email']}'>{$user['email']}</a> <span class='inv'>({$language['Users profile desc18']})</span>";
		else $email = "<a href='mailto:{$user['email']}'>{$user['email']}</a>";

		//-----------------------------------------------------------------
		//  Make Layout
		//-----------------------------------------------------------------

		if($user['aboutme'] != NULL && $user['signature'] == NULL || $user['aboutme'] == NULL && $user['signature'] != NULL) $rowspan = '19';
		elseif($user['aboutme'] != NULL && $user['signature'] != NULL) $rowspan = '22';
		else $rowspan = '18';

		$layout .= "
			<tr>
			<td valign='top' class='con1' rowspan='$rowspan'><table border='0' width='79' height='80' cellspacing='0' cellpadding='0'><tr><td height='80' class='avatar'>".find_avatar($user['avatar'])."</td></tr></table></td>
			<td class='con1' valign='top'>{$language['Users profile desc']}</td>
			<td class='con1'><span class='ok'>{$user['username']}</span></td>
			</tr>
			<tr>
			<td class='con1'>{$language['Users profile desc2']}</td>
			<td class='con1'><span class='bold'>".find_authorization($user['authorization'])."</span></td>
			</tr>
			<tr>
			<td class='con1'>{$language['Users profile desc3']}</td>
			<td class='con1'>$email</td>
			</tr>
			<tr>
			<td class='con1'>{$language['Users profile desc4']}</td>
			<td class='con1'><a href='http://{$user['url']}' target='_blank'>{$user['url']}</a></td>
			</tr>
			<tr>
			<td class='con1'>{$language['Users profile desc5']}</td>
			<td class='con1'>".find_age($user['age'])."</td>
			</tr>
			<tr>
			<td class='con1'>{$language['Users profile desc6']}</td>
			<td class='con1'>".find_flag($user['flag'],$user['location'], true, true)."</td>
			</tr>
			<tr>
			<td class='con1'>{$language['Users profile desc7']}</td>
			<td class='con1'>".today_yesterday($user['registered'])."</td>
			</tr>
			<tr>
			<td class='con1'>{$language['Users profile desc8']}</td>
			<td class='con1'>".last_visit($user['lastvisit'],$user['registered'])."</td>
			</tr>
			<tr>
			<td class='con1'>{$language['Users profile desc9']}</td>
			<td class='con1'>{$user['forumposts']}</td>
			</tr>
			<tr>
			<td class='con1'>{$language['Users profile desc10']}</td>
			<td class='con1'>".find_status($user['status'])."</td>
			</tr>
			<tr class='bottom'>
			<td colspan='2'>{$language['Users profile title3']}</td>
			</tr>
			<tr>
			<td class='con1'>{$language['Users profile desc11']}</td>
			<td class='con1'>{$user['msn']}</td>
			</tr>
			<tr>
			<td class='con1'>{$language['Users profile desc12']}</td>
			<td class='con1'>{$user['yahoo']}</td>
			</tr>
			<tr>
			<td class='con1'>{$language['Users profile desc13']}</td>
			<td class='con1'>{$user['icq']}</td>
			</tr>
			<tr>
			<td class='con1'>{$language['Users profile desc14']}</td>
			<td class='con1'>{$user['aim']}</td>
			</tr>
			<tr>
			<td class='con1'>{$language['Users profile desc15']}</td>
			<td class='con1'>{$user['skype']}</td>
			</tr>
			<tr>
			<td class='con1'>{$language['Users profile desc16']}</td>
			<td class='con1'><a href='$PHP_SELF?n=modules/pm&a=4&d={$user['id']}'>{$language['Users profile desc17']}</a></td>
			</tr>";

		//-----------------------------------------------------------------
		//  Do not show if it's signature field is empty
		//-----------------------------------------------------------------

		if($user['signature'] != NULL)
		{
			$layout .= "
				<tr class='bottom'><td colspan='2'>{$language['Users profile desc19']}</td></tr>
				<tr><td class='con1' colspan='2'>".parse_message($user['signature'])."</td></tr>";
		}

		//-----------------------------------------------------------------
		//  Do not show if it's about me field is empty
		//-----------------------------------------------------------------

		if($user['aboutme'] != NULL)
		{
			$layout .= "
				<tr class='bottom'><td colspan='2'>{$language['Users profile desc20']}</td></tr>
				<tr><td class='con1' colspan='2'>".parse_message($user['aboutme'])."</td></tr>";
		}

		//-----------------------------------------------------------------
		//  Do not show if the user is webmaster
		//-----------------------------------------------------------------

		if($user['authorization'] != 4)
		{
			//-----------------------------------------------------------------
			//  Do not show if the user is the same as the loged in one
			//-----------------------------------------------------------------

			if($is_loged_in == 1) $_SESSION["$security_session"]['id'] = $_SESSION["$security_session"]['id'];
			else $_SESSION["$security_session"]['id'] = NULL;

			if($user['id'] != $_SESSION["$security_session"]['id'])
			{
				//-----------------------------------------------------------------
				//  Do not show if the the loged in guy is guest, user or moderator
				//-----------------------------------------------------------------

				if($is_administrator == 1 || $is_webmaster == 1)
				{
					$layout2 .= "
						<form action='$PHP_SELF?n=modules/users' method='post' name='edituser'>
			 			<tr class='bottom'>
						<td colspan='3'>{$language['Users profile title4']}</td>
						</tr>
						<tr>
						<td class='con1' colspan='2'>{$language['Users edit desc']}</td>
						<td class='con1'><select style='width:170' maxlength='25' class='box' name='editauthorization'>";

						if($user['authorization'] == 1) $layout2 .= "<option value='1' selected>1 ({$language['Authorization 1']})</option>";
						else $layout2 .= "<option value='1'>1 ({$language['Authorization 1']})</option>";

						if($user['authorization'] == 2) $layout2 .= "<option value='2' selected>2 ({$language['Authorization 2']})</option>";
						else $layout2 .= "<option value='2'>2 ({$language['Authorization 2']})</option>";

						if($user['authorization'] == 3) $layout2 .= "<option value='3' selected>3 ({$language['Authorization 3']})</option>";
						else $layout2 .= "<option value='3'>3 ({$language['Authorization 3']})</option>";

						$layout2 .= "</select></td>
						</tr>
						<tr>
						<td class='con1' colspan='2'>{$language['Users edit desc2']}</td>
						<td class='con1'><select style='width:170' maxlength='25' class='box' name='editstatus'>";

						if($user['status'] == "banned") $layout2 .= "<option value='banned' selected>{$language['Users view desc3']}</option>";
						else $layout2 .= "<option value='banned'>{$language['Users view desc3']}</option>";

						if($user['status'] == "activate") $layout2 .= "<option value='activate' selected>{$language['Users view desc2']}</option>";

						if($user['status'] == "ready") $layout2 .= "<option value='ready' selected>{$language['Users view desc']}</option>";
						else $layout2 .= "<option value='ready'>{$language['Users view desc']}</option>";

						$layout2 .= "</select></td>
						</tr>
						<tr>
						<td class='con1' colspan='2'>{$language['Users edit desc3']}</td>
						<td class='con1'><input style='width:170' maxlength='25' class='box' name='editpassword'></td>
						</tr>
						<tr>
						<td class='con1' colspan='2'>{$language['Users edit desc4']}</td>
						<td class='con1'><input type='submit' style='width:170' class='box' value='{$language['Users edit desc5']}'></td>
						</tr>
						<input type='hidden' name='a' value='2'>
						<input type='hidden' name='d' value='{$user['id']}'>
						</form>\n";
				}
			}
		}

		//-----------------------------------------------------------------
		//  Start Layout
		//-----------------------------------------------------------------

		?>
			<table class="main" cellspacing="1" cellpadding="4">
			<col width="1%"><col width="30%"><col width="69%">
			<tr class="head"><td colspan="3"><?= $language['Users profile name'] ?></td></tr>
			<tr class="bottom">
			<td align="center"><?= $language['Users profile title'] ?></td>
			<td colspan="2"><table width="100%" cellspacing="0" cellpadding="0"><tr class="bottom"><td width="70%"><?= $language['Users profile title2'] ?></td><td width="30%" align="right"><span class="inv">#<?= $user['id'] ?></td></tr></table></span></td>
			</tr>
			<?= $layout ?>
			<?= $layout2 ?>
			</table>
		<?

	break;

	//-----------------------------------------------------------------
	//  Edit user case
	//-----------------------------------------------------------------

	case 2:

		//-----------------------------------------------------------------
		//  Check if he has acces
		//-----------------------------------------------------------------

		if(isset($is_administrator) || isset($is_webmaster))
		{
			//-----------------------------------------------------------------
			//  Load the user's row
			//-----------------------------------------------------------------

			$user = $db->getLine("SELECT id, authorization, username, status, ip FROM users WHERE id = '$d'");	

			//-----------------------------------------------------------------
			//  Make Password check
			//-----------------------------------------------------------------

			if($editpassword != FALSE)
				$tmp['password'] = md5($editpassword);

			//-----------------------------------------------------------------
			//  Make Activation check
			//-----------------------------------------------------------------

			if($editstatus != "activate")
			{
				$tmp['multikey'] = NULL;
				$tmp['actime'] = NULL;
			}

			//-----------------------------------------------------------------
			//  Write log + Ready/Banned swich
			//-----------------------------------------------------------------

			if($user['status'] == "ready" || $user['status'] == "forgot")
			{
				if($user['status'] != $editstatus)
				{
					$db->insertRow("log",array('user_id' => ''.$_SESSION["$security_session"]['id'].'','user_user' => ''.$_SESSION["$security_session"]['username'].'','log' => ''.$language['Logs desc3'].' <b>bans</b> the user -> \''.$user['username'].'\'','date' => ''.time().''));
					$db->insertRow("bans",array('user_id' => ''.$_SESSION["$security_session"]['id'].'','user_user' => ''.$_SESSION["$security_session"]['username'].'','banned_id' => ''.$user['id'].'','banned_user' => ''.$user['username'].'','ip' => ''.$user['ip'].'','date' => ''.time().''));
				}
			}
			elseif($user['status'] == "activate"){}
			else
			{
				if($user['status'] != $editstatus)
				{
					$db->insertRow("log",array('user_id' => ''.$_SESSION["$security_session"]['id'].'','user_user' => ''.$_SESSION["$security_session"]['username'].'','log' => ''.$language['Logs desc'].' <b>bans</b> the user -> \''.$user['username'].'\'','date' => ''.time().''));
					$db->deleteRow("bans","banned_id = '$d'");
				}
			}

			//-----------------------------------------------------------------
			//  Write log + Write info in database
			//-----------------------------------------------------------------

			if($user['authorization'] != $editauthorization) $log_changes = " authorization = '$editauthorization' "; else $log_changes = NULL;
			if($user['status'] != $editstatus) $log_changes2 = " status = '$editstatus' "; else $log_changes2 = NULL;
			if($editpassword != FALSE) $log_changes3 = " password = 'PROTECTED' "; else $log_changes3 = NULL;

			if($user['authorization'] != $editauthorization || $user['status'] != $editstatus || $editpassword != FALSE)
				$db->insertRow("log",array('user_id' => ''.$_SESSION["$security_session"]['id'].'','user_user' => ''.$_SESSION["$security_session"]['username'].'','log' => ''.$language['Logs desc2'].' <b>users</b> the user -> \''.$user['username'].'\' to '.$log_changes.''.$log_changes2.''.$log_changes3.'','date' => ''.time().''));

			$tmp['status'] = $editstatus;
			$tmp['authorization'] = $editauthorization;

			$db->updateRow("users",$tmp,"id = $d");

			//-----------------------------------------------------------------
			//  Redirect when finished
			//-----------------------------------------------------------------

			header("location: $PHP_SELF?n=modules/users&a=1&d=$d&i=35");
		}
		else
			header("location: $PHP_SELF?i=2");

	break;

	//-----------------------------------------------------------------
	//  Delete user case
	//-----------------------------------------------------------------

	case 3:

		//-----------------------------------------------------------------
		//  Check if he has acces
		//-----------------------------------------------------------------

		if(isset($is_administrator) || isset($is_webmaster))
		{
			//-----------------------------------------------------------------
			//  Get User
			//-----------------------------------------------------------------

			$user = $db->getLine("SELECT authorization, username FROM users",$d);

			//-----------------------------------------------------------------
			//  Auto Ban Procedure
			//-----------------------------------------------------------------

			if($user['authorization'] == 4)
			{
				$user_self = $db->getLine("SELECT id, username, ip FROM users",$_SESSION["$security_session"]['id']);

				$db->insertRow("log",array('user_user' => 'Auto Protection','log' => ''.$language['Logs desc3'].' <b>bans</b> the user -> \''.$_SESSION["$security_session"]['username'].'\'','date' => ''.time().''));
				$db->insertRow("bans",array('user_user' => 'Auto Protection','banned_id' => ''.$user_self['id'].'','banned_user' => ''.$user_self['username'].'','ip' => ''.$user_self['ip'].'','date' => ''.time().''));

				$user_autoban['status'] = "banned";
				$db->updateRow("users",$user_autoban,"id = {$user_self['id']}");

				header("location: $PHP_SELF"); exit;
			}

			//-----------------------------------------------------------------
			//  Write to log
			//-----------------------------------------------------------------

			$db->insertRow("log",array('user_id' => ''.$_SESSION["$security_session"]['id'].'','user_user' => ''.$_SESSION["$security_session"]['username'].'','log' => ''.$language['Logs desc'].' <b>users</b> the user -> \''.$user['username'].'\'','date' => ''.time().''));

			//-----------------------------------------------------------------
			//  Delete from the database
			//-----------------------------------------------------------------

			$db->deleteRow("users","id = '$d'");

			//-----------------------------------------------------------------
			//  Delete from the calendar
			//-----------------------------------------------------------------

			$db->deleteRow("events","user_id = '$d'");

			//-----------------------------------------------------------------
			//  Delete the user's avatar too
			//-----------------------------------------------------------------

			@unlink(images.'/'.avatars.'/'.$d.'.gif');
			@unlink(images.'/'.avatars.'/'.$d.'.jpg');
			@unlink(images.'/'.avatars.'/'.$d.'.png');

			//-----------------------------------------------------------------
			//  Redirect when finished
			//-----------------------------------------------------------------

			header("location: $PHP_SELF?n=modules/users&s=$s&t=$t&p=$p&i=36");
		}
		else
			header("location: $PHP_SELF?i=2");
	break;

	//-----------------------------------------------------------------
	//  Ban user case
	//-----------------------------------------------------------------

	case 4:
		//-----------------------------------------------------------------
		//  Check if he has acces
		//-----------------------------------------------------------------

		if(isset($is_administrator) || isset($is_webmaster))
		{
			//-----------------------------------------------------------------
			//  Load the user's row
			//-----------------------------------------------------------------

			$user = $db->getLine("SELECT id, authorization, username, ip, status FROM users",$d);

			//-----------------------------------------------------------------
			//  Auto Ban Procedure
			//-----------------------------------------------------------------

			if($user['authorization'] == 4)
			{
				$user_self = $db->getLine("SELECT id, username, ip FROM users",$_SESSION["$security_session"]['id']);

				$db->insertRow("log",array('user_user' => 'Auto Protection','log' => ''.$language['Logs desc3'].' <b>bans</b> the user -> \''.$_SESSION["$security_session"]['username'].'\'','date' => ''.time().''));
				$db->insertRow("bans",array('user_user' => 'Auto Protection','banned_id' => ''.$user_self['id'].'','banned_user' => ''.$user_self['username'].'','ip' => ''.$user_self['ip'].'','date' => ''.time().''));

				$user_autoban['status'] = "banned";
				$db->updateRow("users",$user_autoban,"id = {$user_self['id']}");

				header("location: $PHP_SELF"); exit;
			}

			//-----------------------------------------------------------------
			//  Write log + Ready/Banned swich
			//-----------------------------------------------------------------

			if($user['status'] == "ready" || $user['status'] == "forgot")
			{
				$db->insertRow("log",array('user_id' => ''.$_SESSION["$security_session"]['id'].'','user_user' => ''.$_SESSION["$security_session"]['username'].'','log' => ''.$language['Logs desc3'].' <b>bans</b> the user -> \''.$user['username'].'\'','date' => ''.time().''));
				$db->insertRow("bans",array('user_id' => ''.$_SESSION["$security_session"]['id'].'','user_user' => ''.$_SESSION["$security_session"]['username'].'','banned_id' => ''.$user['id'].'','banned_user' => ''.$user['username'].'','ip' => ''.$user['ip'].'','date' => ''.time().''));
				$users['status'] = "banned";
			}
			else
			{
				$db->insertRow("log",array('user_id' => ''.$_SESSION["$security_session"]['id'].'','user_user' => ''.$_SESSION["$security_session"]['username'].'','log' => ''.$language['Logs desc'].' <b>bans</b> the user -> \''.$user['username'].'\'','date' => ''.time().''));
				$db->deleteRow("bans","banned_id = '$d'");
				$users['status'] = "ready";
			}

			//-----------------------------------------------------------------
			//  Write info in database
			//-----------------------------------------------------------------

			$db->insertRow("log",array('user_id' => ''.$_SESSION["$security_session"]['id'].'','user_user' => ''.$_SESSION["$security_session"]['username'].'','log' => ''.$language['Logs desc2'].' <b>users</b> the user -> \''.$user['username'].'\' to status = \''.$users['status'].'\'','date' => ''.time().''));
			$db->updateRow("users",$users,"id = ".$db->escape($d)."");

			//-----------------------------------------------------------------
			//  Redirect when finished + Trick
			//-----------------------------------------------------------------

			if($user['status'] == "ready" || $user['status'] == "forgot")
				header("location: $PHP_SELF?n=modules/users&s=$s&t=$t&p=$p&i=37");
			else
				header("location: $PHP_SELF?n=modules/users&s=$s&t=$t&p=$p&i=38");
		}
		else
			header("location: $PHP_SELF?i=2");

	break;

	case 5:
		//-----------------------------------------------------------------
		//  Navigation Stuff
		//-----------------------------------------------------------------

		$rows_per_page = 25;
		$numrows = $db->getInfo_countRows("users");

		$lastpage = ceil($numrows/$rows_per_page);
		$p = (int)$p;

		if ($p < 1) $p = 1;
		elseif ($p > $lastpage) $p = $lastpage;

		if($numrows != FALSE) $limit = 'LIMIT ' .($p - 1) * $rows_per_page .',' .$rows_per_page;
		else $limit = NULL;

		//-----------------------------------------------------------------
		//  Sorting Stuff
		//-----------------------------------------------------------------

		if(!isset($s)) $s = 'id'; // Default value
		if(!isset($t)) $t = 'ASC'; // Default value

		$sname1 = "id";
		$sname2 = "flag";
		$sname3 = "username";
		$sname4 = "status";
		$sname5 = "email";
		$sname6 = "authorization";

		if($t == "ASC"){ $t = "DESC"; $t2 = "ASC"; }
		else{ $t = "ASC"; $t2 = "DESC"; }

		if($t == "ASC"){ $t3 = "<img src='templates/$template/images/misc/up.gif' border='0'>";}
		else{ $t3 = "<img src='templates/$template/images/misc/down.gif' border='0'>";}

		if($s == 1) $s = $sname1;
		if($s == 2) $s = $sname2;
		if($s == 3) $s = $sname3;
		if($s == 4) $s = $sname4;
		if($s == 5) $s = $sname5;
		if($s == 6) $s = $sname6;

		//-----------------------------------------------------------------
		//  Load the users table
		//-----------------------------------------------------------------

		$users = $db->getTable("SELECT id, authorization, username, email, flag, location, hideemail, status FROM users ORDER BY '$s' $t2 $limit");

		//-----------------------------------------------------------------
		//  Make a foreach to separate the results
		//-----------------------------------------------------------------

		foreach($users as $idx=>$user)
		{
			//-----------------------------------------------------------------
			//  Count for ID + trick
			//-----------------------------------------------------------------

			if($s == $sname1 && $t == "ASC")
				$idx_count = str_replace("-", "", $idx + (($p - 1) * $rows_per_page + 1) - $numrows - 1);
			else
				$idx_count = $idx + (($p - 1) * $rows_per_page + 1);

			//-----------------------------------------------------------------
			//  Hide email if option says so
			//-----------------------------------------------------------------

			if($user['hideemail'] == 1 && !isset($is_administrator) && !isset($is_webmaster)) $email = "<span class='inv'>{$language['Users view desc4']}</span>";
			elseif($user['hideemail'] == 1) $email = "<a href='mailto:{$user['email']}'>{$user['email']}</a> <span class='inv'>({$language['Users view desc4']})</span>";
			else $email = "<a href='mailto:{$user['email']}'>{$user['email']}</a>";

			//-----------------------------------------------------------------
			//  Make Layout
			//-----------------------------------------------------------------

			$layout .= "
				<tr class='".row2color($idx)."' onMouseOver=this.className='con3' onMouseOut=this.className='".row2color($idx)."' onclick=window.location.href='$PHP_SELF?n=modules/users&a=1&d={$user['id']}'>
				<td align='center'>$idx_count</td>
				<td align='center'>".find_flag($user['flag'],$user['location'])."</td>
				<td><a href='$PHP_SELF?n=modules/users&a=1&d={$user['id']}'>{$user['username']}</td>
				<td>".find_status($user['status'])."</td>
				<td>$email</td>
				<td>".find_authorization($user['authorization'])."</td>";

			if(isset($is_administrator) || isset($is_webmaster))
			{
				if($user['authorization'] == 4) $layout .= "<td><img src='templates/$template/images/buttons/nodelete.gif' border='0' alt='{$language['Users view desc8']}'><img src='templates/$template/images/buttons/noban.gif' border='0' alt='{$language['Users view desc9']}'></td>";
				else
				{
					if($user['status'] == "ready" || $user['status'] == "forgot") $layout .= "<td><a href='$PHP_SELF?n=modules/users&a=3&d={$user['id']}&s=$s&t=$t2&p=$p'><img src='templates/$template/images/buttons/delete.gif' border='0' alt='{$language['Users view desc5']}'></a><a href='$PHP_SELF?n=modules/users&a=4&d={$user['id']}&s=$s&t=$t2&p=$p'><img src='templates/$template/images/buttons/ban.gif' border='0' alt='{$language['Users view desc6']}'></a></td>";
					elseif($user['status'] == "banned") $layout .= "<td><a href='$PHP_SELF?n=modules/users&a=3&d={$user['id']}&s=$s&t=$t2&p=$p'><img src='templates/$template/images/buttons/delete.gif' border='0' alt='{$language['Users view desc5']}'></a><a href='$PHP_SELF?n=modules/users&a=4&d={$user['id']}&s=$s&t=$t2&p=$p'><img src='templates/$template/images/buttons/unban.gif' border='0' alt='{$language['Users view desc7']}'></a></td>";
					else $layout .= "<td><a href='$PHP_SELF?n=modules/users&a=3&d={$user['id']}&s=$s&t=$t2&p=$p'><img src='templates/$template/images/buttons/delete.gif' border='0' alt='{$language['Users view desc5']}'></a><img src='templates/$template/images/buttons/noban.gif' border='0' alt='{$language['Users view desc9']}'></td>";
				}
			}

			$layout .= "</tr>\n";

			//-----------------------------------------------------------------
			//  Start from 1
			//-----------------------------------------------------------------

			$idx ++;
		}

		//-----------------------------------------------------------------
		//  Navigation Code
		//-----------------------------------------------------------------

		if ($p == 1) $nav_prev = "<tr><td class='con1' align='right'>&nbsp;</td>";
		else
		{
			$prevpage = $p-1;
			$nav_prev = "<tr><td class='con1' align='left'><a href='$PHP_SELF?n=modules/users&s=$s&t=$t2&p=$prevpage'>&laquo; {$language['Users previous']}</a></td>";
		}

		$nav_nr = '[ '.paginate($lastpage, $p, $PHP_SELF.'?n=modules/users&s='.$s.'&t='.$t2).' ]';

		if($idx == $numrows) $nav_nr = NULL;

		if ($p == $lastpage)
			$nav_next = "<td class='con1' align='right'>&nbsp;</td></tr>";
		else
		{
			$nextcode = $numrows - $idx * $p;
			if($nextcode > $idx) $how_next = $idx;
			else $how_next = $nextcode;

			$nextpage = $p+1;

			$nav_next = "<td class='con1' align='right'><a href='$PHP_SELF?n=modules/users&s=$s&t=$t2&p=$nextpage'>{$language['Users next']} $how_next &raquo;</a></td></tr>";
		}

		if($idx == $numrows)
		{
			$nav_head = "class='con1'";
			$nav = NULL;
		}
		else
		{
			$nav_head = "class='head'";
			$nav = ''.$nav_prev.''.$nav_next.'';
		}

		//-----------------------------------------------------------------
		//  Start Layout + Navigation
		//-----------------------------------------------------------------

		?>
			<table class="main" cellspacing="1" cellpadding="4">
			<tr class='head'><td colspan='7'><table cellspacing="0" cellpadding="0" width='100%'><tr class='head'><td><?= $language['Users view title6'] ?></td><td align='right'><a href='index.php?n=modules/users'>Thumbnail View</a> | <b>List View</b></td></tr></table></td></tr>
			<tr class="bottom">
			<td align="center"><a href="<?= $PHP_SELF ?>?n=modules/users&s=1&t=<?= $t ?>&p=<?= $p ?>"><? if($s == $sname1) echo $t3; else echo "#" ?></a></td>
			<td width="6%" align="center"><a href="<?= $PHP_SELF ?>?n=modules/users&s=2&t=<?= $t ?>&p=<?= $p ?>"><? if($s == $sname2) echo $t3; else echo $language['Users view title'] ?></a></td>
			<td <? if(isset($is_administrator) || isset($is_webmaster)) {?>width="20%" <? } else {?>width="26%" <? } ?>><a href="<?= $PHP_SELF ?>?n=modules/users&s=3&t=<?= $t ?>&p=<?= $p ?>"><?= $language['Users view title2'] ?> <? if($s == $sname3) echo $t3 ?></a></td>
			<td width="10%"><a href="<?= $PHP_SELF ?>?n=modules/users&s=4&t=<?= $t ?>&p=<?= $p ?>"><?= $language['Users view title3'] ?> <? if($s == $sname4) echo $t3 ?></a></td>
			<td width="39%"><a href="<?= $PHP_SELF ?>?n=modules/users&s=5&t=<?= $t ?>&p=<?= $p ?>"><?= $language['Users view title4'] ?> <? if($s == $sname5) echo $t3 ?></a></td>
			<td width="18%"><a href="<?= $PHP_SELF ?>?n=modules/users&s=6&t=<?= $t ?>&p=<?= $p ?>"><?= $language['Users view title5'] ?> <? if($s == $sname6) echo $t3 ?></a></td>
			<? if(isset($is_administrator) || isset($is_webmaster)) {?><td width="6%">&nbsp;</td> <? } ?>
			</tr>
			<?= $layout ?>
			</table>
			<br>
			<table class="main" cellspacing="1" cellpadding="4" width="100%">
			<col width="50%"><col width="50%">
			<tr <?= $nav_head ?>>
			<td colspan="2">
			<table border="0" cellspacing="0" cellpadding="0" width="100%">
			<col width="50%"><col width="50%">
			<tr class="empty">
			<td align="left"><?= $language['Users nav'] ?> <b><?= $idx ?></b> <?= $language['Users nav2'] ?> <b><?= $numrows ?></b></td>
			<td align="right"><?= $nav_nr ?></td>
			</tr>
			</table>
			</td>
			</tr>
			<?= $nav ?>
			</table>
		<?
	break;

	//-----------------------------------------------------------------
	//  Show Users Default case
	//-----------------------------------------------------------------

	default:

		//-----------------------------------------------------------------
		//  Navigation Stuff
		//-----------------------------------------------------------------

		$rows_per_page = $config['nav_users'];
		$numrows = $db->getInfo_countRows("users");

		$lastpage = ceil($numrows/$rows_per_page);
		$p = (int)$p;

		if ($p < 1) $p = 1;
		elseif ($p > $lastpage) $p = $lastpage;

		if($numrows != FALSE) $limit = 'LIMIT ' .($p - 1) * $rows_per_page .',' .$rows_per_page;
		else $limit = NULL;

		//-----------------------------------------------------------------
		//  Sorting Stuff
		//-----------------------------------------------------------------

		if(!isset($s)) $s = 'id'; // Default value
		if(!isset($t)) $t = 'ASC'; // Default value

		$sname1 = "id";
		$sname2 = "flag";
		$sname3 = "username";
		$sname4 = "status";
		$sname5 = "email";
		$sname6 = "authorization";

		if($t == "ASC"){ $t = "DESC"; $t2 = "ASC"; }
		else{ $t = "ASC"; $t2 = "DESC"; }

		if($t == "ASC"){ $t3 = "<img src='templates/$template/images/misc/up.gif' border='0'>";}
		else{ $t3 = "<img src='templates/$template/images/misc/down.gif' border='0'>";}

		if($s == 1) $s = $sname1;
		if($s == 2) $s = $sname2;
		if($s == 3) $s = $sname3;
		if($s == 4) $s = $sname4;
		if($s == 5) $s = $sname5;
		if($s == 6) $s = $sname6;

		//-----------------------------------------------------------------
		//  Load the users table
		//-----------------------------------------------------------------

		$users = $db->getTable("SELECT id, avatar, authorization, username, email, flag, location, hideemail, status FROM users ORDER BY '$s' $t2 $limit");

		//-----------------------------------------------------------------
		//  Make a foreach to separate the results
		//-----------------------------------------------------------------

		foreach($users as $idx=>$user)
		{
			//-----------------------------------------------------------------
			//  Count for ID + trick
			//-----------------------------------------------------------------

			if($s == $sname1 && $t == "ASC")
				$idx_count = str_replace("-", "", $idx + (($p - 1) * $rows_per_page + 1) - $numrows - 1);
			else
				$idx_count = $idx + (($p - 1) * $rows_per_page + 1);

			//-----------------------------------------------------------------
			//  Hide email if option says so
			//-----------------------------------------------------------------

			if($user['hideemail'] == 1 && !isset($is_administrator) && !isset($is_webmaster)) $email = "<span class='inv'>{$language['Users view desc4']}</span>";
			elseif($user['hideemail'] == 1) $email = "<a href='mailto:{$user['email']}'>{$user['email']}</a> <span class='inv'>({$language['Users view desc4']})</span>";
			else $email = "<a href='mailto:{$user['email']}'>{$user['email']}</a>";
			
			//-----------------------------------------------------------------
			//  Thumbnail Look
			//-----------------------------------------------------------------
			
			if(isset($o))
			{
				//-----------------------------------------------------------------
				//  The Sexual New Look
				//-----------------------------------------------------------------
				
				if($idx == "4" || $idx == "9"  || $idx == "14" || $idx == "19"){
					$tr_open = NULL;
					$tr_close = "</tr><tr class='con1'>";
				}
				else
				{
						$tr_open = NULL;
						$tr_close = NULL;
				}
				
				if($idx == "0")
				{
					$tr_open .= "<tr class='con1' align='center'>";
				}else $tr_open .= NULL;
	
				//-----------------------------------------------------------------
				//  Make Layout
				//-----------------------------------------------------------------
	
				$layout .= "
					$tr_open
					<td height='80' onclick=window.location.href='$PHP_SELF?n=modules/users&a=1&d={$user['id']}' align='center' valign='top'><table border='0' width='79' height='80' cellspacing='0' cellpadding='0'><tr><td height='80' class='avatar'>".find_avatar($user['avatar'])."</td></tr></table><br /><a href='$PHP_SELF?n=modules/users&a=1&d={$user['id']}'>{$user['username']}</td>
					$tr_close";
			}
			else
			{
			
				//-----------------------------------------------------------------
				//  Standard Look
				//-----------------------------------------------------------------
				$layout .= "
				<tr class='".row2color($idx)."' onMouseOver=this.className='con3' onMouseOut=this.className='".row2color($idx)."' onclick=window.location.href='$PHP_SELF?n=modules/users&a=1&d={$user['id']}'>
				<td align='center'>$idx_count</td>
				<td align='center'>".find_flag($user['flag'],$user['location'])."</td>
				<td><a href='$PHP_SELF?n=modules/users&a=1&d={$user['id']}'>{$user['username']}</td>
				<td>".find_status($user['status'])."</td>
				<td>$email</td>
				<td>".find_authorization($user['authorization'])."</td>";

				if(isset($is_administrator) || isset($is_webmaster))
				{
					if($user['authorization'] == 4) $layout .= "<td><img src='templates/$template/images/buttons/no_edit_user.png' border='0' alt='{$language['Users view desc11']}'><img src='templates/$template/images/buttons/nodelete.gif' border='0' alt='{$language['Users view desc8']}'><img src='templates/$template/images/buttons/noban.gif' border='0' alt='{$language['Users view desc9']}'></td>";
					else
					{
						if($user['status'] == "ready" || $user['status'] == "forgot") $layout .= "<td><a href='$PHP_SELF?n=modules/panel&d={$user['id']}'><img src='templates/$template/images/buttons/edit_user.png' border='0' alt='{$language['Users view desc10']}'></a><a href='$PHP_SELF?n=modules/users&a=3&d={$user['id']}&s=$s&t=$t2&p=$p'><img src='templates/$template/images/buttons/delete.gif' border='0' alt='{$language['Users view desc5']}'></a><a href='$PHP_SELF?n=modules/users&a=4&d={$user['id']}&s=$s&t=$t2&p=$p'><img src='templates/$template/images/buttons/ban.gif' border='0' alt='{$language['Users view desc6']}'></a></td>";
						elseif($user['status'] == "banned") $layout .= "<td><a href='$PHP_SELF?n=modules/panel&d={$user['id']}'><img src='templates/$template/images/buttons/edit_user.png' border='0' alt='{$language['Users view desc10']}'></a><a href='$PHP_SELF?n=modules/users&a=3&d={$user['id']}&s=$s&t=$t2&p=$p'><img src='templates/$template/images/buttons/delete.gif' border='0' alt='{$language['Users view desc5']}'></a><a href='$PHP_SELF?n=modules/users&a=4&d={$user['id']}&s=$s&t=$t2&p=$p'><img src='templates/$template/images/buttons/unban.gif' border='0' alt='{$language['Users view desc7']}'></a></td>";
						else $layout .= "<td><a href='$PHP_SELF?n=modules/panel&d={$user['id']}'><img src='templates/$template/images/buttons/edit_user.png' border='0' alt='{$language['Users view desc10']}'></a><a href='$PHP_SELF?n=modules/users&a=3&d={$user['id']}&s=$s&t=$t2&p=$p'><img src='templates/$template/images/buttons/delete.gif' border='0' alt='{$language['Users view desc5']}'></a><img src='templates/$template/images/buttons/noban.gif' border='0' alt='{$language['Users view desc9']}'></td>";
					}
				}

				$layout .= "</tr>\n";
			}

			//-----------------------------------------------------------------
			//  Start from 1
			//-----------------------------------------------------------------

			$idx ++;
		}

		//-----------------------------------------------------------------
		//  Navigation Code
		//-----------------------------------------------------------------

		if ($p == 1) $nav_prev = "<tr><td class='con1' align='right'>&nbsp;</td>";
		else
		{
			$prevpage = $p-1;
			$nav_prev = "<tr><td class='con1' align='left'><a href='$PHP_SELF?n=modules/users&s=$s&t=$t2".(isset($o)?"&o=1":"")."&p=$prevpage'>&laquo; {$language['Users previous']}</a></td>";
		}

		$nav_nr = '[ '.paginate($lastpage, $p, $PHP_SELF.'?n=modules/users&s='.$s.'&t='.$t2.''.(isset($o)?"&o=1":"").'').' ]';

		if($idx == $numrows) $nav_nr = NULL;

		if ($p == $lastpage)
			$nav_next = "<td class='con1' align='right'>&nbsp;</td></tr>";
		else
		{
			$nextcode = $numrows - $idx * $p;
			if($nextcode > $idx) $how_next = $idx;
			else $how_next = $nextcode;

			$nextpage = $p+1;

			$nav_next = "<td class='con1' align='right'><a href='$PHP_SELF?n=modules/users&s=$s&t=$t2".(isset($o)?"&o=1":"")."&p=$nextpage'>{$language['Users next']} $how_next &raquo;</a></td></tr>";
		}

		if($idx == $numrows)
		{
			$nav_head = "class='con1'";
			$nav = NULL;
		}
		else
		{
			$nav_head = "class='head'";
			$nav = ''.$nav_prev.''.$nav_next.'';
		}

		//-----------------------------------------------------------------
		//  Start Layout + Navigation
		//-----------------------------------------------------------------

		?>
			<table class="main" cellspacing="1" cellpadding="4">
			<tr class='head'><td colspan='7'><table cellspacing="0" cellpadding="0" width='100%'><tr class='head'><td><?= $language['Users view title6'] ?></td><td align='right'><?= (!isset($o)?$language['Users view title7']:"<a href='index.php?n=modules/users&p=$p'>{$language['Users view title7']}</a>") ?> | <?= (isset($o)?$language['Users view title8']:"<a href='index.php?n=modules/users&o=1&p=$p'>{$language['Users view title8']}</a>") ?></td></tr></table></td></tr>
			<?= $layout ?>
			</tr>
			</table>
			<table><tr><td></td></tr></table>
			<table class="main" cellspacing="1" cellpadding="4" width="100%">
			<col width="50%"><col width="50%">
			<tr <?= $nav_head ?>>
			<td colspan="2">
			<table border="0" cellspacing="0" cellpadding="0" width="100%">
			<col width="50%"><col width="50%">
			<tr class="empty">
			<td align="left"><?= $language['Users nav'] ?> <b><?= $idx ?></b> <?= $language['Users nav2'] ?> <b><?= $numrows ?></b></td>
			<td align="right"><?= $nav_nr ?></td>
			</tr>
			</table>
			</td>
			</tr>
			<?= $nav ?>
			</table>
		<?
}
?>